package 注解;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.util.Arrays;

@Repeatable(APIS.class)
@interface API {
    String content() default "请添加描述";
}

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface APIS {
    API[] value();
}

@API(content = "学生对象1")
@API(content = "学生对象2")
@API(content = "学生对象3")
class Studentx {
     String name;
}

public class Repeatable使用 {
    public static void main(String[] args) throws  Exception{
        Annotation[] annotations = Studentx.class.getAnnotations();//获取所有注解
        //注解内套注解，即：
        //[@注解.APIS({@注解.API(content="\u5b66\u751f\u5bf9\u8c611"), @注解.API(content="\u5b66\u751f\u5bf9\u8c612"), @注解.API(content="\u5b66\u751f\u5bf9\u8c613")})]
        System.out.println(Arrays.toString(annotations));
        for (Annotation annotation : annotations) {
            System.out.println("APIS= "+annotation.annotationType().getSimpleName());//简化注解名
            APIS api = (APIS) annotation;
            for (API a : api.value()) {
//            	System.out.println(a.annotationType().getName());
                System.out.println(a.content());
            }
        }
        APIS annotation = Studentx.class.getAnnotation(APIS.class);
        System.out.println(annotation.value()[0].content());
        AnnotatedType[] annotatedInterfaces = Studentx.class.getAnnotatedInterfaces();
        for (AnnotatedType annotatedInterface : annotatedInterfaces) {
            System.out.println(annotatedInterface.getType());
        }
        System.out.println(Studentx.class.getComponentType());//null
    }
}
